package it.unibz.easytravel.server;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EasyTravelServlet extends HttpServlet {

	private static final long serialVersionUID = 1839218136422487339L;
	
	public static final String MESSAGE_TYPE = "msg_type";

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		MessageType msgType = parseMessageType(request);
		if (msgType == null) {
			System.out.println("No such message type with such name: " + getMessageTypeName(request));
		}

		msgType.getHandler().handle(request, response);
	}
	
	private String getMessageTypeName(HttpServletRequest request) {
		return request.getHeader(MESSAGE_TYPE);
	}
	

	private MessageType parseMessageType(HttpServletRequest request) {
		return MessageType.parseType(getMessageTypeName(request));
	}
	
	
	
}
